package emulator;

import java.util.HashMap;

import keyboard.Keyboard;

public class ResultCostCalculatorScanning extends ResultCostCalculator {
	public ResultCostCalculatorScanning(String strategy, int dictSize) {
		super(strategy, dictSize);
		this.costType = "scanning";
	}
	
	@Override
	public float CalnCost(Keyboard keyboard, Result result) {
		String word = result.GetWord();
		float cost = 0f;
		
		for (int i = 0; i < word.length(); i++) {
			keyboard.GroupingStaticKeyboard(result.GetExpression(i));
			HashMap<Character, Character> groupsKey = keyboard.GetGroupsKey();
			char key = groupsKey.get(word.charAt(i));
			
			for (int j = 0; j < 26; j++) {
				if ((char)('a' + j) == groupsKey.get((char)('a' + j))) {
					if ('a' + j <= key)
						cost += 1;
				}
			}
		}
		
		cost += result.GetPriority();
		return cost;
	}
}
